//
//  CollectionNumberManager.m
//  CaiPiao
//
//  Created by l wb on 2018/5/22.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "CollectionNumberManager.h"

@implementation CollectionNumberManager

+(void)collectionNumberWithArray:(NSArray *)dataArr{
    if (dataArr.count != 0) {
        for (int i=0; i<dataArr.count; i++) {
            CollectionNumberModel *model = dataArr[i];
            BmobObject *object = [BmobObject objectWithClassName:@"NumberRecord"];
            [object setObject:model.type forKey:@"type"];
            [object setObject:model.number forKey:@"number"];
            [object setObject:kUserID forKey:@"uid"];
            NSString *logoName;
            NSInteger typeID = [model.type integerValue];
            switch (typeID) {
                case 4:
                    logoName = @"R-大乐透";
                    break;
                case 3:
                    logoName = @"R-双色球";
                    break;
                case 6:
                    logoName = @"R-排列三";
                    break;
                case 5:
                    logoName = @"R-福彩3D";
                    break;
                case 9:
                    logoName = @"R-快3";
                    break;
                case 7:
                    logoName = @"R-11选5";
                    break;
                default:
                    break;
            }
        
            
            
            [object setObject:logoName forKey:@"logoName"];
            
            
            [object saveInBackgroundWithResultBlock:^(BOOL isSuccessful, NSError *error) {
                if (isSuccessful) {
                    [EasyTextView showText:@"收藏成功,请到个人中心->我的追号查看"];
                }
            }];
        }
    }
}
+(void)getCollectionNumberDataWithCompleteHandle:(void(^)(NSArray*arr))complete{
    NSMutableArray *dataArr =[NSMutableArray new];
    BmobQuery *query = [BmobQuery queryWithClassName:@"NumberRecord"];
    [query orderByDescending:@"createdAt"];
    [query whereKey:@"uid" equalTo:kUserID];
    [query findObjectsInBackgroundWithBlock:^(NSArray *array, NSError *error) {
//        NSLog(@"%@-=======%@",array,error);
        if (array) {
            for (BmobObject *object in array) {
                NSLog(@"object=======%@",object);
                CollectionNumberModel *model = [CollectionNumberModel new];
                model.logoName = [object objectForKey:@"logoName"];
                model.number = [object objectForKey:@"number"];
                model.date = [object objectForKey:@"createdAt"];
                model.objectID = [object objectForKey:@"objectId"];
                NSInteger typeID = [[object objectForKey:@"type"] integerValue];
                switch (typeID) {
                    case 4:
                        model.type = @"大乐透";
                        break;
                    case 3:
                        model.type = @"双色球";
                        break;
                    case 6:
                        model.type = @"排列三";
                        break;
                    case 5:
                        model.type = @"福彩3D";
                        break;
                    case 9:
                        model.type = @"快3";
                        break;
                    case 7:
                        model.type = @"11选5";
                        break;
                    default:
                        break;
                }
                NSLog(@"model======%@",model);
                [dataArr addObject:model];
                
                
            }
            complete(dataArr);
        }
        
        
    }];
    
   
    
    
}




@end
